load("@cmake_configure_file//:cmake_configure_file.bzl", "cmake_configure_file")
load("//bzl:cpp_library.bzl", "cpp_library")

package(default_visibility = ["//visibility:public"])

cpp_library(
    name = "concurrent_bit_set",
    hdrs = ["ConcurrentBitSet.h"],
    deps = [":portability"],
)

cpp_library(
    name = "atomic_hash_array",
    hdrs = ["AtomicHashArray.h"],
    textual_hdrs = ["AtomicHashArray-inl.h"],
    deps = [
        ":thread_cached_int",
        ":utility",
        "//folly/detail:atomic_hash_utils",
        "//folly/detail:iterators",
        "//folly/hash",
        "//folly/lang:bits",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "atomic_hash_map",
    hdrs = ["AtomicHashMap.h"],
    textual_hdrs = ["AtomicHashMap-inl.h"],
    deps = [
        ":atomic_hash_array",
        ":c_portability",
        ":likely",
        ":thread_cached_int",
        "//folly/container:foreach",
        "//folly/detail:atomic_hash_utils",
        "//folly/detail:iterators",
        "//folly/hash",
    ],
)

cpp_library(
    name = "atomic_linked_list",
    hdrs = [
        "AtomicIntrusiveLinkedList.h",
        "AtomicLinkedList.h",
    ],
    deps = [":memory"],
)

cpp_library(
    name = "atomic_unordered_map",
    hdrs = ["AtomicUnorderedMap.h"],
    deps = [
        ":conv",
        ":likely",
        ":random",
        ":scope_guard",
        ":traits",
        "//folly/detail:atomic_unordered_map_utils",
        "//folly/lang:bits",
        "//folly/portability:sys_mman",
        "//folly/portability:unistd",
    ],
)

cpp_library(
    name = "base64",
    hdrs = ["base64.h"],
    deps = [
        ":c_portability",
        ":portability",
        "//folly/detail/base64_detail:base64_api",
        "//folly/detail/base64_detail:base64_common",
        "//folly/lang:exception",
        "//folly/memory:uninitialized_memory_hacks",
    ],
)

cpp_library(
    name = "benchmark_util",
    hdrs = [
        "BenchmarkUtil.h",
    ],
    deps = [
        ":portability",
        "//folly/lang:hint",
    ],
)

cpp_library(
    name = "benchmark",
    srcs = ["Benchmark.cpp"],
    hdrs = ["Benchmark.h"],
    deps = [
        ":benchmark_util",
        ":file_util",
        ":map_util",
        ":portability",
        ":preprocessor",
        ":range",
        ":scope_guard",
        ":string",
        ":traits",
        "//folly/detail:perf_scoped",
        "//folly/functional:invoke",
        "//folly/json:dynamic",
        "//folly/lang:hint",
        "//folly/portability:gflags",
        "@boost.function_types",
        "@boost.regex",
        "@glog",
    ],
)

cpp_library(
    # @shim
    name = "bits",
    hdrs = ["Bits.h"],
    deps = ["//folly/lang:bits"],
)

cpp_library(
    name = "c_portability",
    hdrs = ["CPortability.h"],
    deps = ["//folly/portability:config"],
)

cpp_library(
    name = "cancellation_token",
    srcs = ["CancellationToken.cpp"],
    hdrs = ["CancellationToken.h"],
    textual_hdrs = ["CancellationToken-inl.h"],
    deps = [
        ":cpp_attributes",
        ":function",
        ":optional",
        "//folly:scope_guard",
        "//folly/lang:new",
        "//folly/portability:memory",
        "//folly/synchronization/detail:sleeper",
        "@glog",
    ],
)

cpp_library(
    name = "chrono",
    hdrs = ["Chrono.h"],
    deps = [
        ":portability",
        "//folly/lang:exception",
        "//folly/portability:time",
    ],
)

cpp_library(
    name = "clock_gettime_wrappers",
    srcs = ["ClockGettimeWrappers.cpp"],
    hdrs = ["ClockGettimeWrappers.h"],
    linkopts = select({
        "@platforms//os:linux": [
            "-ldl",
            "-lrt",
        ],
        "//conditions:default": [],
    }),
    deps = [
        ":c_portability",
        ":likely",
        "//folly/portability:time",
    ],
)

cpp_library(
    name = "concurrent_lazy",
    hdrs = ["ConcurrentLazy.h"],
    deps = [
        "//folly/functional:invoke",
        "//folly/synchronization:delayed_init",
    ],
)

cpp_library(
    name = "concurrent_skip_list",
    hdrs = ["ConcurrentSkipList.h"],
    textual_hdrs = ["ConcurrentSkipList-inl.h"],
    deps = [
        ":constexpr_math",
        ":likely",
        ":memory",
        ":thread_local",
        "//folly/detail:iterators",
        "//folly/synchronization:micro_spin_lock",
        "@boost.random",
        "@glog",
    ],
)

cmake_configure_file(
    name = "config_h_gen",
    src = "//CMake:folly-config.h.cmake",
    out = "folly-config.h",
    cmakelists = ["//:CMakeLists.txt"],
    defines = [
        "FOLLY_HAVE_LIBGLOG",
        "FOLLY_HAVE_LIBGFLAGS",
        # TODO(kgk): Enable once @jemalloc is added to bcr. See:
        # https://github.com/bazelbuild/bazel-central-registry/issues/3757
        # undef FOLLY_USE_JEMALLOC
    ] + select({
        "@platforms//os:windows": [
            # TODO(kgk): What defines should be set here?
        ],
        "@platforms//os:macos": [
            # TODO(kgk): What defines should be set here?
        ],
        "@platforms//os:linux": [
            "FOLLY_HAVE_PTHREAD",
            "FOLLY_HAVE_PTHREAD_ATFORK",
            "FOLLY_HAVE_ACCEPT4",
            "FOLLY_HAVE_GETRANDOM",
            "FOLLY_HAVE_PREADV",
            "FOLLY_HAVE_PWRITEV",
            "FOLLY_HAVE_CLOCK_GETTIME",
            "FOLLY_HAVE_PIPE2",
            "FOLLY_HAVE_IFUNC",
            "FOLLY_HAVE_UNALIGNED_ACCESS",
            "FOLLY_HAVE_VLA",
            "FOLLY_HAVE_WEAK_SYMBOLS",
            "FOLLY_HAVE_LINUX_VDSO",
            "FOLLY_HAVE_MALLOC_USABLE_SIZE",
            # undef FOLLY_HAVE_INT128_T
            "FOLLY_HAVE_WCHAR_SUPPORT",
            "FOLLY_HAVE_EXTRANDOM_SFMT19937",
            "HAVE_VSNPRINTF_ERRORS",
            # TODO(kgk): Enable once @libunwind is added to bcr. See:
            # https://github.com/bazelbuild/bazel-central-registry/issues/3655
            # undef FOLLY_HAVE_LIBUNWIND
            # TODO(kgk): Enable once @libdwarf is added to bcr. See:
            # https://github.com/bazelbuild/bazel-central-registry/issues/3653
            # undef FOLLY_HAVE_DWARF
            "FOLLY_HAVE_ELF",
            "FOLLY_HAVE_SWAPCONTEXT",
            "FOLLY_HAVE_BACKTRACE",
            "FOLLY_USE_SYMBOLIZER",
            "FOLLY_HAVE_SHADOW_LOCAL_WARNINGS",
            "FOLLY_HAVE_LIBLZ4",
            "FOLLY_HAVE_LIBLZMA",
            "FOLLY_HAVE_LIBSNAPPY",
            "FOLLY_HAVE_LIBZ",
            "FOLLY_HAVE_LIBZSTD",
            "FOLLY_HAVE_LIBBZ2",
            # undef FOLLY_SUPPORT_SHARED_LIBRARY
        ],
    }),
    visibility = ["//visibility:public"],
)

cpp_library(
    name = "config",
    hdrs = [":config_h_gen"],
)

cpp_library(
    name = "constexpr_math",
    hdrs = ["ConstexprMath.h"],
    deps = [
        ":portability",
        "//folly/lang:checked_math",
        "//folly/portability:constexpr",
    ],
)

cpp_library(
    name = "constructor_callback_list",
    hdrs = ["ConstructorCallbackList.h"],
    deps = [
        ":format",
        ":function",
        ":shared_mutex",
        "//folly/detail:static_singleton_manager",
    ],
)

cpp_library(
    name = "conv",
    srcs = ["Conv.cpp"],
    hdrs = ["Conv.h"],
    deps = [
        ":c_portability",
        ":demangle",
        ":expected",
        ":fbstring",
        ":likely",
        ":portability",
        ":range",
        ":traits",
        ":unit",
        ":utility",
        "//folly/lang:exception",
        "//folly/lang:pretty",
        "//folly/lang:safe_assert",
        "//folly/lang:to_ascii",
        "//folly/portability:math",
        "@double-conversion",
        "@fast_float",
    ],
)

cpp_library(
    name = "cpp_attributes",
    hdrs = ["CppAttributes.h"],
    deps = [":portability"],
)

cpp_library(
    name = "cpu_id",
    hdrs = ["CpuId.h"],
    deps = [":portability"],
)

cpp_library(
    name = "default_keep_alive_executor",
    hdrs = ["DefaultKeepAliveExecutor.h"],
    deps = [
        ":executor",
        "//folly/executors:sequenced_executor",
        "//folly/synchronization:baton",
        "@glog",
    ],
)

cpp_library(
    name = "demangle",
    srcs = ["Demangle.cpp"],
    hdrs = ["Demangle.h"],
    # TODO(kgk): Support binutils?
    # os_deps = [(
    #     "linux",
    #     ["third-party//binutils:iberty"],
    # )],
    deps = [
        ":c_portability",
        ":cpp_attributes",
        ":fbstring",
        ":utility",
        "//folly/functional:invoke",
        "//folly/lang:c_string",
        "//folly/portability:config",
    ],
)

cpp_library(
    name = "discriminated_ptr",
    hdrs = ["DiscriminatedPtr.h"],
    deps = [
        ":likely",
        ":portability",
        "//folly/detail:discriminated_ptr_detail",
        "@glog",
    ],
)

cpp_library(
    name = "dynamic",
    hdrs = [
        "DynamicConverter.h",
        "dynamic.h",
        "dynamic-inl.h",
        "json.h",
    ],
    deps = ["//folly/json:dynamic"],
)

cpp_library(
    name = "exception",
    hdrs = ["Exception.h"],
    deps = [
        ":conv",
        ":fbstring",
        ":likely",
        ":portability",
        "//folly/portability:sys_types",
    ],
)

cpp_library(
    name = "exception_string",
    srcs = ["ExceptionString.cpp"],
    hdrs = ["ExceptionString.h"],
    deps = [
        ":demangle",
        ":fbstring",
        "//folly/lang:exception",
        "//folly/lang:type_info",
    ],
)

cpp_library(
    name = "exception_wrapper",
    srcs = ["ExceptionWrapper.cpp"],
    hdrs = ["ExceptionWrapper.h"],
    textual_hdrs = ["ExceptionWrapper-inl.h"],
    deps = [
        ":c_portability",
        ":cpp_attributes",
        ":demangle",
        ":exception_string",
        ":fbstring",
        ":glog",
        ":portability",
        ":traits",
        ":utility",
        "//folly/functional:traits",
        "//folly/lang:assume",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "executor",
    srcs = ["Executor.cpp"],
    hdrs = ["Executor.h"],
    deps = [
        ":exception_string",
        ":function",
        ":optional",
        ":portability",
        ":range",
        ":utility",
        "//folly/lang:exception",
        "@glog",
    ],
)

cpp_library(
    name = "expected",
    hdrs = ["Expected.h"],
    deps = [
        ":c_portability",
        ":cpp_attributes",
        ":likely",
        ":portability",
        ":preprocessor",
        ":traits",
        ":unit",
        ":utility",
        "//folly/coro:coroutine",
        "//folly/lang:exception",
        "//folly/lang:hint",
    ],
)

cpp_library(
    name = "fbstring",
    hdrs = ["FBString.h"],
    deps = [
        ":c_portability",
        ":cpp_attributes",
        ":likely",
        ":portability",
        ":traits",
        "//folly/hash",
        "//folly/lang:assume",
        "//folly/lang:checked_math",
        "//folly/lang:exception",
        "//folly/memory:malloc",
        "@fmt",
    ],
)

cpp_library(
    name = "fbvector",
    hdrs = ["FBVector.h"],
    deps = ["//folly/container:fbvector"],
)

cpp_library(
    name = "file",
    srcs = ["File.cpp"],
    hdrs = ["File.h"],
    deps = [
        ":exception",
        ":exception_wrapper",
        ":expected",
        ":file_util",  # @manual
        ":portability",
        ":range",
        ":scope_guard",
        "//folly/portability:fcntl",
        "//folly/portability:fmt_compile",
        "//folly/portability:sys_file",
        "//folly/portability:unistd",
        "@glog",
    ],
)

cpp_library(
    name = "file_util",
    srcs = ["FileUtil.cpp"],
    hdrs = ["FileUtil.h"],
    deps = [
        ":portability",
        ":range",
        ":scope_guard",
        "//folly/detail:file_util_detail",
        "//folly/detail:file_util_vector_detail",
        "//folly/net:net_ops",
        "//folly/net:network_socket",
        "//folly/portability:fcntl",
        "//folly/portability:sockets",
        "//folly/portability:stdlib",
        "//folly/portability:sys_file",
        "//folly/portability:sys_stat",
        "//folly/portability:sys_uio",
        "//folly/portability:unistd",
    ],
)

cpp_library(
    name = "fingerprint",
    srcs = ["Fingerprint.cpp"],
    hdrs = ["Fingerprint.h"],
    deps = [
        ":portability",
        ":range",
        ":utility",
        "//folly/detail:fingerprint_polynomial",
    ],
)

cpp_library(
    name = "fixed_string",
    hdrs = ["FixedString.h"],
    deps = [
        ":constexpr_math",
        ":portability",
        ":range",
        ":utility",
        "//folly/lang:exception",
        "//folly/lang:ordering",
        "//folly/portability:constexpr",
    ],
)

cpp_library(
    name = "fmt_utility",
    srcs = ["FmtUtility.cpp"],
    hdrs = ["FmtUtility.h"],
    deps = [
        ":cpp_attributes",
        ":range",
        ":string",
        "//folly/ssl:openssl_hash",
        "@fmt",
    ],
)

cpp_library(
    name = "format",
    srcs = ["Format.cpp"],
    hdrs = [
        "Format.h",
        "FormatArg.h",
    ],
    textual_hdrs = ["Format-inl.h"],
    deps = [
        ":c_portability",
        ":constexpr_math",
        ":conv",
        ":cpp_attributes",
        ":exception",
        ":format_traits",
        ":likely",
        ":map_util",
        ":portability",
        ":range",
        ":string",
        ":traits",
        "//folly/container:array",
        "//folly/lang:exception",
        "//folly/lang:to_ascii",
        "//folly/portability:windows",
        "@double-conversion",
    ],
)

cpp_library(
    name = "format_traits",
    hdrs = ["FormatTraits.h"],
)

cpp_library(
    name = "function",
    hdrs = ["Function.h"],
    deps = [
        ":cpp_attributes",
        ":portability",
        ":traits",
        "//folly/functional:invoke",
        "//folly/lang:align",
        "//folly/lang:exception",
        "//folly/lang:new",
    ],
)

cpp_library(
    name = "group_varint",
    srcs = ["GroupVarint.cpp"],
    hdrs = ["GroupVarint.h"],
    deps = [
        ":portability",
        ":range",
        "//folly/container:array",
        "//folly/detail:group_varint_detail",
        "//folly/lang:bits",
        "//folly/portability:builtins",
        "@glog",
    ],
)

cpp_library(
    name = "hash",
    hdrs = ["Hash.h"],
    deps = ["//folly/hash"],
)

cpp_library(
    name = "indestructible",
    hdrs = ["Indestructible.h"],
    deps = [
        ":traits",
        ":utility",
    ],
)

cpp_library(
    name = "indexed_mem_pool",
    hdrs = ["IndexedMemPool.h"],
    deps = [
        ":portability",
        "//folly/concurrency:cache_locality",
        "//folly/portability:sys_mman",
        "//folly/portability:unistd",
        "//folly/synchronization:atomic_struct",
    ],
)

cpp_library(
    name = "intrusive_list",
    hdrs = ["IntrusiveList.h"],
    deps = ["//folly/container:intrusive_list"],
)

cpp_library(
    name = "json",
    deps = [":dynamic"],
)

cpp_library(
    name = "json_pointer",
    hdrs = ["json_pointer.h"],
    deps = ["//folly/json:json_pointer"],
)

cpp_library(
    name = "json_patch",
    hdrs = ["json_patch.h"],
    deps = ["//folly/json:json_patch"],
)

cpp_library(
    name = "lazy",
    hdrs = ["Lazy.h"],
    deps = [
        ":optional",
        "//folly/functional:invoke",
    ],
)

cpp_library(
    name = "likely",
    hdrs = ["Likely.h"],
    deps = ["//folly/lang:builtin"],
)

cpp_library(
    name = "glog",
    hdrs = ["GLog.h"],
    deps = [
        ":likely",
        "@glog",
    ],
)

cpp_library(
    name = "map_util",
    hdrs = ["MapUtil.h"],
    deps = ["//folly/container:map_util"],
)

cpp_library(
    name = "math",
    hdrs = ["Math.h"],
)

cpp_library(
    name = "memset-impl",
    srcs = ["FollyMemset.cpp"] + select({
        "@platforms//cpu:x86_64": ["memset.S"],
        "@bazel_tools//src/conditions:linux_aarch64": ["memset_select_aarch64.cpp"],
        "//conditions:default": [],
    }),
    copts = select({
        "@platforms//cpu:x86_64": ["-mavx2"],
        "//conditions:default": [],
    }),
    deps = select({
        "@bazel_tools//src/conditions:linux_aarch64": [
            "//folly/external/aor:memset_aarch64",  # @manual
        ],
        "//conditions:default": [],
    }),
)

# This exports the symbol __folly_memset to C++ via a header.
cpp_library(
    name = "memset",
    hdrs = ["FollyMemset.h"],
    deps = [
        ":memset-impl",  # @manual
    ],
)

# This overrides the libc memset with __folly_memset.
cpp_library(
    name = "memset-use",
    srcs = ["FollyMemset.cpp"] + select({
        "@platforms//cpu:x86_64": ["memset.S"],
        "@bazel_tools//src/conditions:linux_aarch64": ["memset_select_aarch64.cpp"],
        "//conditions:default": [],
    }),
    copts = select({
        "@platforms//cpu:x86_64": ["-mavx2"],
        "//conditions:default": [],
    }),
    defines = ["FOLLY_MEMSET_IS_MEMSET"],
    deps = select({
        "@bazel_tools//src/conditions:linux_aarch64": [
            "//folly/external/aor:memset_aarch64",  # @manual
        ],
        "//conditions:default": [],
    }),
)

# This adds the symbol __folly_memcpy but does not replace the default memcpy.
cpp_library(
    name = "memcpy-impl",
    srcs = ["FollyMemcpy.cpp"] + select({
        "@platforms//cpu:x86_64": ["memcpy.S"],
        "@bazel_tools//src/conditions:linux_aarch64": ["memcpy_select_aarch64.cpp"],
        "//conditions:default": [],
    }),
    copts = select({
        "@platforms//cpu:x86_64": ["-mavx2"],
        "//conditions:default": [],
    }),
    deps = select({
        "@bazel_tools//src/conditions:linux_aarch64": [
            "//folly/external/aor:memcpy_aarch64",  # @manual
        ],
        "//conditions:default": [],
    }),
)

# This exports the symbol __folly_memcpy to C++ via a header.
cpp_library(
    name = "memcpy",
    hdrs = ["FollyMemcpy.h"],
    deps = [
        ":memcpy-impl",  # @manual
    ],
)

# This overrides the libc memcpy with __folly_memcpy.
cpp_library(
    name = "memcpy-use",
    srcs = ["FollyMemcpy.cpp"] + select({
        "@platforms//cpu:x86_64": ["memcpy.S"],
        "@bazel_tools//src/conditions:linux_aarch64": ["memcpy_select_aarch64.cpp"],
        "//conditions:default": [],
    }),
    copts = select({
        "@platforms//cpu:x86_64": [
            "-march=haswell",
            "-mavx2",
        ],
        "//conditions:default": [],
    }),
    defines = ["FOLLY_MEMCPY_IS_MEMCPY"],
    deps = select({
        "@bazel_tools//src/conditions:linux_aarch64": [
            "//folly/external/aor:memcpy_aarch64-use",  # @manual
        ],
        "//conditions:default": [],
    }),
)

cpp_library(
    name = "memory",
    hdrs = ["Memory.h"],
    deps = [
        ":constexpr_math",
        ":likely",
        ":portability",
        ":traits",
        ":utility",
        "//folly/functional:invoke",
        "//folly/lang:align",
        "//folly/lang:exception",
        "//folly/lang:thunk",
        "//folly/memory:malloc",
        "//folly/portability:config",
        "//folly/portability:constexpr",
        "//folly/portability:malloc",
    ],
)

cpp_library(
    name = "micro_lock",
    srcs = ["MicroLock.cpp"],
    hdrs = ["MicroLock.h"],
    deps = [
        ":optional",
        ":portability",
        "//folly/detail:futex",
        "//folly/portability:asm",
    ],
)

cpp_library(
    # @shim
    name = "micro_spin_lock",
    hdrs = ["MicroSpinLock.h"],
    deps = ["//folly/synchronization:micro_spin_lock"],
)

cpp_library(
    name = "move_wrapper",
    hdrs = ["MoveWrapper.h"],
)

cpp_library(
    name = "mpmc_pipeline",
    hdrs = ["MPMCPipeline.h"],
    deps = [
        ":portability",
        "//folly/detail:mpmc_pipeline_detail",
        "@glog",
    ],
)

cpp_library(
    name = "mpmc_queue",
    hdrs = ["MPMCQueue.h"],
    deps = [
        ":traits",
        "//folly/concurrency:cache_locality",
        "//folly/detail:turn_sequencer",
        "//folly/portability:unistd",
    ],
)

cpp_library(
    name = "network_address",
    srcs = [
        "IPAddress.cpp",
        "IPAddressV4.cpp",
        "IPAddressV6.cpp",
        "MacAddress.cpp",
        "SocketAddress.cpp",
    ],
    hdrs = [
        "IPAddress.h",
        "IPAddressException.h",
        "IPAddressV4.h",
        "IPAddressV6.h",
        "MacAddress.h",
        "SocketAddress.h",
    ],
    deps = [
        ":c_portability",
        ":constexpr_math",
        ":conv",
        ":exception",
        ":expected",
        ":fbstring",
        ":format",
        ":optional",
        ":portability",
        ":range",
        ":scope_guard",
        ":small_vector",
        ":string",
        ":unit",
        "//folly/detail:ip_address",
        "//folly/detail:ip_address_source",
        "//folly/hash",
        "//folly/lang:bits",
        "//folly/lang:exception",
        "//folly/net:net_ops",
        "//folly/net:network_socket",
        "//folly/portability:sockets",
        "@boost.container_hash",
        "@fmt",
    ],
)

cpp_library(
    name = "observer_container",
    hdrs = ["ObserverContainer.h"],
    deps = [
        ":constructor_callback_list",
        ":function",
        ":optional",
        ":scope_guard",
        ":small_vector",
        "//folly/io/async:destructor_check",
        "@glog",
    ],
)

cpp_library(
    name = "optional",
    hdrs = ["Optional.h"],
    deps = [
        ":portability",
        ":traits",
        ":utility",
        "//folly/coro:coroutine",
        "//folly/hash:traits",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "replaceable",
    hdrs = ["Replaceable.h"],
    deps = [
        ":portability",
        ":traits",
        ":utility",
    ],
)

cpp_library(
    name = "overload",
    hdrs = ["Overload.h"],
    deps = [
        ":portability",
        ":traits",
        "//folly/functional:invoke",
    ],
)

cpp_library(
    name = "packed_sync_ptr",
    hdrs = ["PackedSyncPtr.h"],
    deps = [
        ":portability",
        "//folly/synchronization:small_locks",
        "@glog",
    ],
)

cpp_library(
    name = "padded",
    hdrs = ["Padded.h"],
    deps = [
        ":portability",
        ":traits",
        "//folly/functional:invoke",
        "//folly/portability:sys_types",
        "@boost.iterator",
    ],
)

cpp_library(
    name = "portability",
    hdrs = ["Portability.h"],
    deps = [
        ":c_portability",
        "//folly/portability:config",
    ],
)

cpp_library(
    name = "preprocessor",
    hdrs = ["Preprocessor.h"],
    deps = [":c_portability"],
)

cpp_library(
    name = "poly",
    hdrs = ["Poly.h"],
    textual_hdrs = ["Poly-inl.h"],
    deps = [
        ":c_portability",
        ":cpp_attributes",
        ":poly_exception",
        ":traits",
        "//folly/detail:poly_detail",
        "//folly/detail:typelist",
        "//folly/lang:assume",
    ],
)

cpp_library(
    name = "poly_exception",
    hdrs = ["PolyException.h"],
    deps = ["//folly:c_portability"],
)

cpp_library(
    name = "producer_consumer_queue",
    hdrs = ["ProducerConsumerQueue.h"],
    deps = ["//folly/concurrency:cache_locality"],
)

cpp_library(
    name = "random",
    srcs = ["Random.cpp"],
    hdrs = ["Random.h"],
    textual_hdrs = ["Random-inl.h"],
    # TODO(kgk): Is the bazel equivalent of this needed?
    #os_deps = [(
    #    "windows",
    #    [
    #        "fbsource//third-party/toolchains/win:advapi32.lib",
    #    ],
    #)],
    deps = [
        ":cpp_attributes",
        ":portability",
        ":singleton_thread_local",
        ":thread_local",
        ":traits",
        "//folly/detail:file_util_detail",
        "//folly/functional:invoke",
        "//folly/lang:bits",
        "//folly/portability:config",
        "//folly/portability:sys_time",
        "//folly/portability:unistd",
        "//folly/synchronization:relaxed_atomic",
        "@glog",
    ],
)

cpp_library(
    name = "range",
    hdrs = ["Range.h"],
    deps = [
        ":cpu_id",
        ":likely",
        ":portability",
        ":traits",
        "//folly/detail:range_common",
        "//folly/detail:range_simd",
        "//folly/hash:spooky_hash_v2",
        "//folly/lang:c_string",
        "//folly/lang:exception",
        "//folly/portability:constexpr",
        "@fmt",
    ],
)

cpp_library(
    # @shim
    name = "rw_spin_lock",
    hdrs = ["RWSpinLock.h"],
    deps = ["//folly/synchronization:rw_spin_lock"],
)

cpp_library(
    name = "scope_guard",
    srcs = ["ScopeGuard.cpp"],
    hdrs = ["ScopeGuard.h"],
    deps = [
        ":portability",
        ":preprocessor",
        ":utility",
        "//folly/lang:exception",
        "//folly/lang:uncaught_exceptions",
    ],
)

cpp_library(
    name = "shared_mutex",
    srcs = ["SharedMutex.cpp"],
    hdrs = ["SharedMutex.h"],
    deps = [
        ":c_portability",
        ":cpp_attributes",
        ":indestructible",
        ":likely",
        "//folly/chrono:hardware",
        "//folly/concurrency:cache_locality",
        "//folly/detail:futex",
        "//folly/lang:exception",
        "//folly/portability:asm",
        "//folly/portability:sys_resource",
        "//folly/synchronization:lock",
        "//folly/synchronization:relaxed_atomic",
        "//folly/synchronization:sanitize_thread",
        "//folly/system:thread_id",
    ],
)

cpp_library(
    name = "singleton",
    srcs = ["Singleton.cpp"],
    hdrs = ["Singleton.h"],
    linkopts = select({
        "@platforms//os:linux": [
            "-ldl",
            "-lrt",
        ],
        "//conditions:default": [],
    }),
    textual_hdrs = ["Singleton-inl.h"],
    deps = [
        ":cancellation_token",
        ":demangle",
        ":exception",
        ":executor",
        ":memory",
        ":scope_guard",
        ":synchronized",
        "//folly/concurrency:core_cached_shared_ptr",
        "//folly/concurrency/memory:read_mostly_shared_ptr",
        "//folly/detail:singleton",
        "//folly/detail:static_singleton_manager",
        "//folly/experimental/symbolizer",
        "//folly/hash",
        "//folly/lang:exception",
        "//folly/lang:safe_assert",
        "//folly/memory:sanitize_leak",
        "//folly/portability:config",
        "//folly/portability:fmt_compile",
        "//folly/synchronization:baton",
        "@fmt",
        "@glog",
    ],
)

cpp_library(
    name = "singleton_thread_local",
    srcs = ["SingletonThreadLocal.cpp"],
    hdrs = ["SingletonThreadLocal.h"],
    deps = [
        ":scope_guard",
        ":thread_local",
        "//folly/detail:iterators",
        "//folly/detail:singleton",
        "//folly/detail:unique_instance",
        "//folly/functional:invoke",
        "//folly/lang:hint",
    ],
)

cpp_library(
    name = "small_vector",
    hdrs = ["small_vector.h"],
    deps = ["//folly/container:small_vector"],
)

cpp_library(
    name = "sorted_vector_types",
    hdrs = ["sorted_vector_types.h"],
    deps = ["//folly/container:sorted_vector_types"],
)

cpp_library(
    name = "spin_lock",
    hdrs = ["SpinLock.h"],
    deps = [
        ":portability",
        "//folly/synchronization:small_locks",
    ],
)

cpp_library(
    name = "stop_watch",
    hdrs = ["stop_watch.h"],
    deps = [
        ":chrono",
        ":utility",
        "//folly/portability:time",
    ],
)

cpp_library(
    name = "string",
    srcs = ["String.cpp"],
    hdrs = ["String.h"],
    textual_hdrs = ["String-inl.h"],
    deps = [
        ":conv",
        ":cpp_attributes",
        ":exception_string",
        ":optional",
        ":portability",
        ":range",
        ":scope_guard",
        ":traits",
        ":unit",
        "//folly/container:array",
        "//folly/container:reserve",
        "//folly/detail:simple_simd_string_utils",
        "//folly/detail:split_string_simd",
        "@glog",
    ],
)

cpp_library(
    name = "subprocess",
    srcs = ["Subprocess.cpp"],
    hdrs = ["Subprocess.h"],
    deps = [
        ":conv",
        ":exception",
        ":file",
        ":file_util",
        ":function",
        ":map_util",
        ":optional",
        ":portability",
        ":range",
        ":scope_guard",
        ":string",
        "//folly/gen:string",
        "//folly/io:iobuf",
        "//folly/lang:assume",
        "//folly/logging",
        "//folly/portability:dirent",
        "//folly/portability:fcntl",
        "//folly/portability:sockets",
        "//folly/portability:stdlib",
        "//folly/portability:sys_resource",
        "//folly/portability:sys_syscall",
        "//folly/portability:unistd",
        "//folly/system:at_fork",
        "//folly/system:shell",
        "@boost.container",
        "@boost.range",
        "@boost.utility",
    ],
)

cpp_library(
    name = "synchronized",
    hdrs = ["Synchronized.h"],
    deps = [
        ":function",
        ":likely",
        ":preprocessor",
        ":shared_mutex",
        ":traits",
        ":utility",
        "//folly/container:foreach",
        "//folly/functional:apply_tuple",
        "//folly/synchronization:lock",
        "@glog",
    ],
)

cpp_library(
    name = "synchronized_ptr",
    hdrs = ["SynchronizedPtr.h"],
    deps = [":synchronized"],
)

cpp_library(
    name = "thread_cached_int",
    hdrs = ["ThreadCachedInt.h"],
    deps = [
        ":likely",
        ":thread_local",
    ],
)

cpp_library(
    name = "thread_local",
    hdrs = ["ThreadLocal.h"],
    deps = [
        ":likely",
        ":portability",
        ":scope_guard",
        ":shared_mutex",
        "//folly/detail:thread_local_detail",
    ],
)

cpp_library(
    name = "timeout_queue",
    srcs = ["TimeoutQueue.cpp"],
    hdrs = ["TimeoutQueue.h"],
    deps = ["@boost.multi_index"],
)

cpp_library(
    name = "token_bucket",
    hdrs = ["TokenBucket.h"],
    deps = [
        ":constexpr_math",
        ":likely",
        ":optional",
        "//folly/concurrency:cache_locality",
    ],
)

cpp_library(
    name = "traits",
    hdrs = ["Traits.h"],
    deps = [":portability"],
)

cpp_library(
    name = "try",
    srcs = ["Try.cpp"],
    hdrs = ["Try.h"],
    textual_hdrs = ["Try-inl.h"],
    deps = [
        ":exception_wrapper",
        ":likely",
        ":memory",
        ":portability",
        ":unit",
        ":utility",
        "//folly/functional:invoke",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "unicode",
    srcs = ["Unicode.cpp"],
    hdrs = ["Unicode.h"],
    deps = [
        ":conv",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "unit",
    hdrs = ["Unit.h"],
)

cpp_library(
    name = "uri",
    srcs = ["Uri.cpp"],
    hdrs = ["Uri.h"],
    textual_hdrs = ["Uri-inl.h"],
    deps = [
        ":conv",
        ":expected",
        ":string",
        "//folly/hash",
        "@boost.regex",
    ],
)

cpp_library(
    name = "utf8_string",
    hdrs = ["UTF8String.h"],
    deps = [
        ":range",
        "@boost.regex",
    ],
)

# For things that would go in c++ stdlib <utility>:
cpp_library(
    name = "utility",
    hdrs = ["Utility.h"],
    deps = [
        ":c_portability",
        ":portability",
        ":traits",
    ],
)

cpp_library(
    name = "varint",
    hdrs = ["Varint.h"],
    deps = [
        ":conv",
        ":expected",
        ":likely",
        ":portability",
        ":range",
    ],
)

cpp_library(
    name = "virtual_executor",
    hdrs = ["VirtualExecutor.h"],
    deps = ["//folly/executors:virtual_executor"],
)

cpp_library(
    name = "maybe_managed_ptr",
    hdrs = ["MaybeManagedPtr.h"],
)
